package com.west_traveler.tiyutoutiao.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.west_traveler.tiyutoutiao.R;
import com.west_traveler.tiyutoutiao.databinding.FragmentHeadLineViewPagerBinding;

import java.util.List;

/**
 * created by Wang_JunJie at 2016/12/20
 */
public class HeadLineViewPagerAdapter extends FragmentPagerAdapter {
    private Context context;
    private List<Fragment> list;
    public HeadLineViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        FragmentHeadLineViewPagerBinding binding = DataBindingUtil.inflate(LayoutInflater.from(container.getContext()), R.layout.fragment_head_line_view_pager, container, false);
        View view = binding.getRoot();
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;
        container.removeView(view);
    }
}
